/*
	FileName : JT_C_REC_Ver.c
	Description :
		Manage the JT_C Version record.
	
	Created on 2017.11.05 by WFL.

	Revision History:

*/


/* Includes ------------------------------------------------------------------*/



#include "JT_C_REC_Ver.h"


uint8_t JTC_ver[JTC_VER_MAX_LEN];


//------------------------------------------------------------------------------
void JTC_REC_VER_getUnit(uint8_t *readBuf, uint8_t *verBuf, uint8_t unit)
{
	uint32_t i;
	
	i = unit * JTC_VER_UNIT_LEN;
	
	if((i+JTC_VER_UNIT_LEN) >= JTC_VER_MAX_LEN)
		return;		///error offset
	
	readBuf[0] = verBuf[i++];	///main
	readBuf[1] = verBuf[i++];	///sub
	readBuf[2] = verBuf[i++];	///Year
	readBuf[3] = verBuf[i++];	///Month
	readBuf[4] = verBuf[i++];	///Date
	return;
}
void JTC_REC_VER_setUnit(uint8_t *writeBuf, uint8_t *verBuf, uint8_t unit)
{
	uint32_t i;
	
	i = unit * JTC_VER_UNIT_LEN;
	
	if((i+JTC_VER_UNIT_LEN) >= JTC_VER_MAX_LEN)
		return;		///error offset
	
	verBuf[i++] = writeBuf[0];	///main
	verBuf[i++] = writeBuf[1];	///sub
	verBuf[i++] = writeBuf[2];	///Year
	verBuf[i++] = writeBuf[3];	///Month
	verBuf[i++] = writeBuf[4];	///Date
	return;
}
void JTC_REC_VER_getWhole(uint8_t *readBuf, uint8_t *verBuf)
{
	uint32_t i;
	for(i=0; i< (JTC_VER_UNIT_TOLNUMBER*JTC_VER_UNIT_LEN); i++)
		readBuf[i] = verBuf[i];
	return;
}
void JTC_REC_VER_setWhole(uint8_t *writeBuf, uint8_t *verBuf)
{
	uint32_t i;
	for(i=0; i< (JTC_VER_UNIT_TOLNUMBER*JTC_VER_UNIT_LEN); i++)
		verBuf[i] = writeBuf[i];
	return;
}
//------------------------------------------------------------------------------

void JTC_REC_VER_setUnitByUart(uint8_t *uartVerDataAddr, uint8_t *verBuf, uint8_t unit)
{
	uint32_t i;
	
	i = unit * JTC_VER_UNIT_LEN;
	
	if((i+JTC_VER_UNIT_LEN) >= JTC_VER_MAX_LEN)
		return;		///error offset
	
	uartVerDataAddr++;///Version type(BIOS or APP)
	verBuf[i++] = *uartVerDataAddr++;///main
	verBuf[i++] = *uartVerDataAddr++;///sub
	uartVerDataAddr++;///Year---2000
	verBuf[i++] = *uartVerDataAddr++;///Year
	verBuf[i++] = *uartVerDataAddr++;///Month
	verBuf[i++] = *uartVerDataAddr++;///Date
	return;
}

void JTC_REC_VER_setByUart(uint8_t *uartVerDataAddr, uint8_t *verBuf)
{
	///------------------External version info-------------------------------
	///Sample CPU: BIOS and APP
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_SAM_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_SAM_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	///Main CPU: BIOS and APP(uart data don't contain REC cpu version data)
	///
	///A control/jm1/jm2, B control/jm1/jm2, LJB
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_ACTRL_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_ACTRL_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_AJM1_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_AJM1_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_AJM2_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_AJM2_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BCTRL_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BCTRL_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BJM1_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BJM1_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BJM2_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_BJM2_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_LJB_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_EXT_LJB_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	///----------------------Internal version info--------------------------------
	///Sample CPU: BIOS and APP
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_SAM_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_SAM_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	///Main CPU: BIOS and APP
	///
	///USB: APP
	///
	///A control/jm1/jm2, B control/jm1/jm2, LJB
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_ACTRL_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_ACTRL_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_AJM1_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_AJM1_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_AJM2_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_AJM2_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BCTRL_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BCTRL_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BJM1_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BJM1_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BJM2_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_BJM2_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_LJB_BIOS);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	JTC_REC_VER_setUnitByUart(uartVerDataAddr, verBuf, JTC_VER_UNIT_INN_LJB_APP);
	uartVerDataAddr += JTC_VER_uartUNIT_LEN;
	return;
}
//-----------------------------------------------------------------------------------------
void JTC_REC_VER_init(uint8_t *j_Ver)
{
	uint32_t i;
	
	for(i=0; i< JTC_VER_MAX_LEN; i++)
		j_Ver[i] = 0;
	return;
}

///EOF
